package com.asiainfo.kbisheet.components.condition.ddlist
{
	import com.asiainfo.kbisheet.common.Util;
	import com.asiainfo.kbisheet.components.condition.ConditionInput;
	import com.asiainfo.kbisheet.components.condition.ConditionItem;
	import com.asiainfo.kbisheet.vo.DimVO;
	import com.asiainfo.kbisheet.vo.LabelValueVO;
	import com.asiainfo.kbisheet.vo.WhereVO;
	
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.collections.IList;
	import mx.collections.XMLListCollection;
	
	import spark.components.DropDownList;
	
	/**
	 * 下拉列表(DDList)输入条件的单组件呈现
	 */
	public class ConditionInputDDList extends ConditionInput
	{

		[Bindable]
		private var dataList:ArrayCollection = new ArrayCollection();
		
		private var ddList:DropDownList;
		
		public function ConditionInputDDList(parent:ConditionItem)
		{
			super(parent);
		}
		
		public function set selectedIndex(value:int):void
		{
			ddList.selectedIndex = value;
		}

		public function set selectedItem(value:*):void
		{
			ddList.selectedItem = value;
		}
		
		public function set dataProvider(value:IList):void
		{
			ddList.dataProvider = value;
		}
		
		override public function get value():String{
			if(Util.isNull(_parent.preset)){
				if(ddList.selectedItem != null){
					if(LabelValueVO(ddList.selectedItem).value != null && LabelValueVO(ddList.selectedItem).value.length>0)
						return LabelValueVO(ddList.selectedItem).value;
					else
						return null;
				}
				else{
					return null;
				}					
			}
			else{
				return _parent.preset;
			}
		}
		
		override protected function createChildren():void {
			ddList = new DropDownList();
			ddList.addEventListener("change", onChange);
			ddList.dataProvider = dataList;
			ddList.requireSelection = true;
			addElement(ddList);
		}
	}
}